//
//  RadioDetailsTableCell.m
//  aMoment
//
//  Created by dllo on 15/10/3.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "RadioDetailsTableCell.h"
#import "AllHeaderFiles.h"

@implementation RadioDetailsTableCell

- (void)dealloc
{
    [_coverImageView release];
    [_titleLabel release];
    [_listenNumField release];
    [_playImageView release];
    [_radioDetails release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _coverImageView = [[UIImageView alloc] init];
    _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    _coverImageView.clipsToBounds = YES;
    [self.contentView addSubview:_coverImageView];
    [_coverImageView release];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:FONTSIZE_MIDDLE];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    _listenNumField = [[UITextField alloc] init];
    _listenNumField.font = [UIFont systemFontOfSize:FONTSIZE_SMALL];
    _listenNumField.enabled = NO;
    _listenNumField.textColor = FONTCOLOR_GRAY;
    UIImageView *leftView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];
    leftView.image = [UIImage imageNamed:@"iconfont-listen"];
    _listenNumField.leftView = leftView;
    _listenNumField.leftViewMode = UITextFieldViewModeAlways;
    [leftView release];
    [self.contentView addSubview:_listenNumField];
    [_listenNumField release];
    
    _playImageView = [[UIImageView alloc] init];
//    _playImageView.backgroundColor = [UIColor cyanColor];
    _playImageView.image = [UIImage imageNamed:@"iconfont-radioplay"];
    [self.contentView addSubview:_playImageView];
    [_playImageView release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _coverImageView.frame = CGRectMake(20 * FIT_WIDTH, 10 * FIT_HEIGHT, 50 * FIT_WIDTH, 50 * FIT_WIDTH);
    _playImageView.frame = CGRectMake(SCREEN_WIDTH - _coverImageView.X - IMAGE_32, self.contentView.Height / 2 - IMAGE_32 / 2, IMAGE_32, IMAGE_32);
    _titleLabel.frame = CGRectMake(_coverImageView.X + _coverImageView.Width + 5 * FIT_WIDTH, _coverImageView.Y, SCREEN_WIDTH - 40 * FIT_WIDTH - _coverImageView.Width - 5 * FIT_WIDTH - _playImageView.Width, _coverImageView.Height / 2);
    _listenNumField.frame = CGRectMake(_titleLabel.X, _titleLabel.Y + _titleLabel.Height, _titleLabel.Width, _titleLabel.Height);
}

- (void)setRadioDetails:(RadioDetails *)radioDetails
{
    if (_radioDetails != radioDetails) {
        [_radioDetails release];
        _radioDetails = [radioDetails retain];
    }
    [_coverImageView setImageWithURL:[NSURL URLWithString:_radioDetails.coverimg] placeholderImage:[UIImage imageNamed:@"placeholder-cd"]];
    _titleLabel.text = _radioDetails.title;
    _listenNumField.text = _radioDetails.musicVisit;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
